const app = getApp()
Page({
  data: {
    name: '',
    pro: 0,
    inputUsernameDate:"123",
    inputPasswordDate:"123",
    loginBtnTxt:"登录",
    btnLoading:false,
    disabled:false,
    inputUserName: '',
    inputPassword: '',
    logIcon:"../../images/logIcon.png",
    pwdIcon:"../../images/pwdIcon.png",
    key:"1"
  },
  // 获取用户输入章节信息
  getName(e) {
    this.setData({
      name: e.detail.value
    })
  },
  //获取用户输入正确率信息
  getNum(e) {
    this.setData({
      pro: Number(e.detail.value),
    })
  },
  //提交数据
  add() {
    let name = this.data.name
    let pro = this.data.pro
    if (!name) {
      wx.showToast({
        icon: "error",
        title: '请输入章节名',
      })
      return
    }
    if (!pro) {
      wx.showToast({
        icon: "error",
        title: '请输入正确率',
      })
      return
    }
    if (pro > 1 || pro < 0) {
      wx.showToast({
        icon: "error",
        title: '请输入0-1之间的值',
      })
      return
    }
    var pingjun = 0
    var fenshu = [0, 0, 0, 0, 0, 0, 0, 0, 0]
    fenshu.push(pro)
    var total = 0
    for (var i = 0; i < 10; i++) {
      total = total + fenshu[i]
    }
    pingjun = total / 10
    console.log('pingjun', pingjun)
    wx.cloud.database().collection('studyRecords')
      .add({
        data: {
          name: app.globalData.name,
          mod1: name,
          pro: pingjun,
          pro1: pingjun*10,
          fenshu: fenshu,
          sum: pro * 10,
          oldTime1: new Date().getTime() / 1000 / 60 / 60 - 449300,
          newTime1: new Date().getTime() / 1000 / 60 / 60 - 449300
        }
      })
      .then(res => {
        console.log("提交成功", res)
        wx.showToast({
          title: '提交成功',
          icon: 'success',
          duration: 2000
        });
        wx.navigateBack({
          delta: 0,
        })
      })
      .catch(res => {
        console.log("提交失败", res)
      })
  },
})